﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TranThiQuynhUyen
{
    class Cau2DAL
    {   
        public Cau2DAL()
        {}

        public  DataTable DOCDANHSACHSINHVIEN()
        {
            SqlConnection co = new SqlConnection();
            co.ConnectionString = @"Data Source=QUYNHUYEN\SQLEXPRESS;Initial Catalog=sinhvien; User Id=sa; Password=sa";
            co.Open();
            SqlCommand cmd = new SqlCommand("SELECT * FROM tbsinhvien", co);
            SqlDataReader dr = cmd.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Load(dr);
            return dt;

        }
        public  void THEMSINHVIEN(string masv, string ho, string ten, string ngaysinh, string gioitinh,string makhoa)
        {
            SqlConnection co = new SqlConnection();
            co.ConnectionString = @"Data Source=QUYNHUYEN\SQLEXPRESS;Initial Catalog=sinhvien; User Id=sa; Password=sa";
            co.Open();
            SqlCommand cmd = new SqlCommand("insert into tbsinhvien values(N'" + masv + "',N'" + ho + "',N'" + ten + "','" + ngaysinh + "',N'" + gioitinh + "','" + makhoa + "')", co);
            cmd.ExecuteNonQuery();
            co.Close();
        }
        public void XOAHOADON(string masv)
        {
            SqlConnection co = new SqlConnection();
            co.ConnectionString = @"Data Source=QUYNHUYEN\SQLEXPRESS;Initial Catalog=sinhvien; User Id=sa; Password=sa";
            co.Open();
            SqlCommand cmd = new SqlCommand("DELETE FROM tbsinhvien  WHERE masv='" + masv + "'", co);
            cmd.ExecuteNonQuery();
            co.Close();

        }
    }
}
